package com.wedimob.scrapper.data;

import java.net.URI;

import org.jsoup.Connection.Response;

/**
 * Content container.
 * 
 * @author melouadi
 * 
 */
public class Content {
	/**
	 * Time of creation.
	 */
	private long creationTime;

	/**
	 * Source.
	 */
	private URI uri;

	/**
	 * Response.
	 */
	private Response response;

	/**
	 * Error.
	 */
	private Throwable e;

	/**
	 * Type.
	 */
	private ContentType type;
	
	/**
	 * copy constructor.
	 * 
	 * @param content
	 *            content
	 */
	public Content(final Content content) {
		super();
		this.uri = content.uri;
		this.response = content.response;
		this.type = content.type;
		this.e = content.e;
		creationTime = System.currentTimeMillis();
	}

	/**
	 * Valid response constructor.
	 * 
	 * @param aUri
	 *            source
	 * @param aResponse
	 *            response
	 */
	public Content(final URI aUri, final Response aResponse) {
		super();
		this.uri = aUri;
		this.response = aResponse;
		this.type = ContentType.create(aResponse.contentType());
		creationTime = System.currentTimeMillis();
	}

	/**
	 * Non valid response constructor.
	 * 
	 * @param aUri
	 *            source
	 * @param aE
	 *            error
	 */
	public Content(final URI aUri, final Throwable aE) {
		super();
		this.uri = aUri;
		this.e = aE;
		creationTime = System.currentTimeMillis();
	}

	/**
	 * Retrieve response.
	 * 
	 * @return response
	 */
	public Response getResponse() {
		return response;
	}

	/**
	 * Retrieve error.
	 * 
	 * @return error
	 */
	public Throwable getError() {
		return e;
	}

	/**
	 * Retrieve source.
	 * 
	 * @return source
	 */
	public URI getUri() {
		return uri;
	}

	/**
	 * Retrieve type.
	 * 
	 * @return type
	 */
	public ContentType getType() {
		return type;
	}

	/**
	 * Retrieve creation time.
	 * 
	 * @return creation time
	 */
	public long getCreationTime() {
		return creationTime;
	}

}